package com.itheima.utills;

import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.InvocationTargetException;

/**
 * @Author Azer
 * @LOVE,,,
 * @Date 2021/9/19 14:34
 */
public class CommonUtils {

    public static <T> T CommonPopulate(Class<T> clazz, HttpServletRequest request){
        T obj =null;

        //获取无参构造器无参构造器
        try {
            obj = clazz.newInstance();
            BeanUtils.populate(obj,request.getParameterMap());
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        return obj;
    }
}
